<?php
require_once('../../../../../global.php');
$gender = !$_POST['gender'] ? 0 : $_POST['gender'];
$file_giftname = "hack_gift_randname".$gender.".php";
if(!file_exists(D_P.'data/bbscache/'.$file_giftname)){gift_randname($gender);}
require_once(D_P.'data/bbscache/'.$file_giftname);
if($timestamp - $gift_createtime > 300 ){gift_randname($gender);}
$key = Rand(0,count($randname)-1);
$username = $randname[$key];
header("Content-Type: text/xml;charset=UTF-8 ");
echo"<?xml version=\"1.0\" encoding=\"UTF-8\"?><ajax><![CDATA[".$username."]]></ajax>";exit;

function gift_randname($gender)
{
	global $winduid,$db,$file_giftname,$timestamp;
	if($gender){$gender_sql = " AND gender=$gender";}
	$query = $db->query("SELECT * FROM pw_members Where uid<>$winduid$gender_sql ORDER BY RAND() LIMIT 100");
	
	$str = "\$gift_createtime = $timestamp;\r\n";
	$str .= "\$randname=array(";
	$k = 0;
	while($rt = $db->fetch_array($query))
	{
		$username = $rt['username'];
		$str .= "'$k'=>'$username',\r\n";
		$k++;
	}
	$str .= ")";
	writeover(D_P.'data/bbscache/'.$file_giftname,"<?php\r\n$str\r\n?>");
}
?>